﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BlogManager.Configuration;

namespace BlogManager
{
    public partial class OptionsForm : Form
    {
        public OptionsForm()
        {
            InitializeComponent();
            this.txtUsername.Text = Settings.Default.Username;
            this.txtPassword.Text = "aaaaaaaaaaaaaaaaaaa";
            this.txtBlogUrl.Text = Settings.Default.BlogUrl;
            this.txtBlogId.Text = Settings.Default.BlogId;
            this.txtTags.Text = Settings.Default.TagsPlaceholder;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            Settings.Default.BlogId = this.txtBlogId.Text;
            Settings.Default.BlogUrl = this.txtBlogUrl.Text;
            Settings.Default.Username = this.txtUsername.Text;
            Settings.Default.TagsPlaceholder = this.txtTags.Text;
            if (savePassword)
                Settings.Default.Password = this.txtPassword.Text;
            
            Settings.Default.Save();
            this.DialogResult = DialogResult.OK;
        }

        bool savePassword = false;
        private void txtPassword_TextChanged(object sender, EventArgs e)
        {
            savePassword = true;
        }
    }
}
